//-----------------------------------------------------------------
// Includes
//-----------------------------------------------------------------
#include <Viewer/Grid.hpp>
#include <GL/gl.h>

//-----------------------------------------------------------------
// Constantes
//-----------------------------------------------------------------
#define DEFAUT_GRID_COLOR_R 0.9f
#define DEFAUT_GRID_COLOR_V 0.9f
#define DEFAUT_GRID_COLOR_B 0.9f

namespace Viewer
{

	Grid::Grid( int ecart, 
				  int nLargeur, 
				  int nLongueur ):
	Node(-(nLargeur / 2), 0, -(nLongueur / 2),DEFAUT_GRID_COLOR_R,DEFAUT_GRID_COLOR_V,DEFAUT_GRID_COLOR_B), 
	offset(ecart), width(nLargeur), length(nLongueur)
	{
		
	}

	Grid::Grid( const Grid & grille ):Node( grille )
	{
		offset = grille.offset;
		width = grille.width;
		length = grille.length;
	}

	Grid::~Grid()
	{

	}

	void Grid::Draw()
	{
		material.Draw();
		Vector normale(0.0f,1.0f,0.0f);

		for( int i = 0; i <= length; ++i )
		{
			// Dessin des lignes 
			glBegin( GL_LINES );
			glVertex3f( 0, 0, i*offset );
			glNormal3f(normale.x,normale.y,normale.z);
			glVertex3f( offset*width, 0, i*offset );
			glNormal3f(normale.x,normale.y,normale.z);
			glEnd();

			// Dessin des colonnes
			glBegin( GL_LINES );
			glVertex3f( i*offset, 0, 0 );
			glNormal3f(normale.x,normale.y,normale.z);
			glVertex3f( i*offset, 0, offset*length );
			glNormal3f(normale.x,normale.y,normale.z);
			glEnd();
		}		
	}

	Node * Grid::CreateCopy()
	{
		return new Grid( *this );
	}

}
